#include <iostream>
#include <chrono>
#include <thread>
#include <sstream>
#include <iomanip>
#include <ctime>

using std::cout;
using std::endl;

std::string nowTime()
{
    auto now = std::chrono::system_clock::now();
    auto inTime = std::chrono::system_clock::to_time_t(now);

    std::stringstream ss;
    ss << std::put_time(localtime(&inTime), "%Y-%m-%d %X");
    return ss.str();
}

void printTime()
{
    std::string str = nowTime();
    cout << "now is:" << str << endl;
}

void sleepThread()
{
    std::this_thread::sleep_for(std::chrono::seconds(3));
    cout << "[" << nowTime() << "]" << "[thread-" << std::this_thread::get_id() << "] is waking up" << endl;
}

void loop_thread()
{
    for (int i = 0; i < 10; i++)
    {
        cout << "[" << nowTime() << "]" << "[thread-" << std::this_thread::get_id() << "] print:" << i << endl;
    }
}

int main()
{
    cout << "Hello World!" << endl;
    printTime();

    std::thread t1(sleepThread);
    std::thread t2(loop_thread);

    t1.join();
    t2.join();

    printTime();
    return 0;
}
